#    MythMobile, a Django interface to MythTV for mobile devices
#    Copyright (C) 2011 Andrew Wilkinson (andrewjwilkinson@gmail.com)
#
#     This program is free software; you can redistribute it and/or modify
#     it under the terms of the GNU General Public License as published by
#     the Free Software Foundation; either version 2 of the License, or
#     (at your option) any later version.
#
#     This program is distributed in the hope that it will be useful,
#     but WITHOUT ANY WARRANTY; without even the implied warranty of
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#     GNU General Public License for more details.
#
#     You should have received a copy of the GNU General Public License along
#     with this program; if not, write to the Free Software Foundation, Inc.,
#     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import time

from django.shortcuts import render_to_response
from django.template import RequestContext

from app.utils import send_backend_msg

def live_channel(req, channel_no):
    send_backend_msg("begin_live_tv", "iphone", int(channel_no))

    channel_name = send_backend_msg("get_channel_name", int(channel_no))

    files = send_backend_msg("get_playlist_entries", "iphone", int(channel_no))
    
    return render_to_response("iphone/live_channel.html", { "channel_number": channel_no, "channel_name": channel_name, "enough_files": len(files) > 1 }, context_instance=RequestContext(req))

def live_channel_playlist(req, channel_no):
    files = send_backend_msg("get_playlist_entries", "iphone", int(channel_no))

    files = [f.split("/")[-1] for f in files]
    print files
    return render_to_response("iphone/playlist.m3u8", { "root": "/data/line-iphone-%s" % (channel_no, ), "files": files, "is_complete": False }, context_instance=RequestContext(req))
